package com.kangaroo;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.kangaroo.filter.JwtFilter;
import com.kangaroo.service.UserService;
@EnableTransactionManagement
@SpringBootApplication
@MapperScan("com.kangaroo.dao")
public class PaymentApplication extends SpringBootServletInitializer {
	@Resource
	private UserService userService;
	  /**
	   * 1、 extends WebMvcConfigurationSupport
	   * 2、重写下面方法;
	   * setUseSuffixPatternMatch : 设置是否是后缀模式匹配，如“/user”是否匹配/user.*，默认真即匹配；
	   * setUseTrailingSlashMatch : 设置是否自动后缀路径模式匹配，如“/user”是否匹配“/user/”，默认真即匹配；
	   */
	  @Override
	    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
	        return application.sources(PaymentApplication.class);
	    }
	public static void main(String[] args) {
		SpringApplication.run(PaymentApplication.class, args);
	}
	
	 @Bean
		public FilterRegistrationBean jwtFilter() {
			final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
			registrationBean.setFilter(new JwtFilter(userService));
			List<String> urlPatterns = new ArrayList<String>();  
			urlPatterns.add("/auth/*");
			registrationBean.setUrlPatterns(urlPatterns);
			return registrationBean;
		}
	
}
